package com.ars.common.dao.activity;

import com.ars.common.beans.Active.Active;
import com.ars.common.utils.DBUtil;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.TreeMap;

/**
 * ClassName: FindActivityByTypeServlet
 * Package: com.ars.common.dao.activity
 * Description:
 *
 * @Author: Bryan Long
 * @Create: 2024/8/8 - 14:57
 * @Version: v1.0
 */
public class FindActivityByType {
    public static TreeMap <Integer, Active> findActivityByType(String type) throws SQLException, ClassNotFoundException {
        String sql = "-- 左连接查询\n" +
                "SELECT a.id, a.name,a.creatorID, a.beginTime, a.endTime, a.type\n" +
                "FROM active a\n" +
                "where a.type = ?" ;

        PreparedStatement ps = DBUtil.getConnection().prepareStatement(sql);

        ps.setString(1, type);

        ResultSet rs = ps.executeQuery();

        TreeMap<Integer, Active> Tmap = new TreeMap<Integer, Active>();

        while(rs.next()) {
            Active active = new Active();
            active.setId(rs.getInt("id"));
            active.setName(rs.getString("name"));
            active.setCreatorID(rs.getString("creatorID"));
            active.setBeginTime(rs.getString("beginTime"));
            active.setEndTime(rs.getString("endTime"));
            active.setType(rs.getString("type"));
            Tmap.put(active.getId(), active);

//            System.out.println(active.toString());
        }

        return Tmap;

    }
}
